<%@ page import="cz.tpj.logic.*" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="cz.tpj.database.mesto.*" %>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <%= Navigation.getHead("<script type='text/javascript' src='" + Navigation.CONTEXT + Navigation.JS_JQVERY +"'></script>") %>
    <%= Navigation.getStartBody() %>
    <%= Navigation.getNavigationPanel(Navigation.JSP_SEARCH_ROAD, request) %>
    	<div id="<%= Navigation.DIV_CENTER %>">
                <h1>Stranka vyhledavani</h1>
                <%
                final String START_CITY  = "start_city";
                final String END_CITY    = "end_city";
                %>
                <p>
                <label>Z:</label><br/>
                <select name="<%= START_CITY%>" class="nastavovac">
                <%
                Table_city tableCity = Table_city.getInstance();
                //promenna pro jednotliva mesta
                City city;
                //ziska vsecky mesta v databazi
                ArrayList<City> allCityes = tableCity.getAllCity();
                Iterator<City> itCityes = allCityes.iterator();
                //prochazeni jednotlivych mest a pridani do rozbalovaciho comboboxu
                while(itCityes.hasNext()){
                    //nacte jedno mesto
                    city = itCityes.next();
                    //prida do comboboxu
                    out.println("<option selected value='"+city.getMapyNazov()+"'>"+city.getName()+"</option> ");
                }
                %>
                </select>
                <br/>
                <label>Do:</label><br/>
                <select name="<%= END_CITY %>" class="nastavovac">
                <%
                //----------------cilove mesto------------
                itCityes = allCityes.iterator();
                //prochazeni jednotlivych mest a pridani do rozbalovaciho comboboxu
                while(itCityes.hasNext()){
                    //nacte jedno mesto
                    city = itCityes.next();
                    //prida do comboboxu
                    out.println("<option selected value='"+city.getMapyNazov()+"'>"+city.getName()+"</option> ");
                }
                %>
                </select>
                <br/>
                <a href="<%= Navigation.CONTEXT + Navigation.JSP_SEARCH_ROAD %>" class="odkaz_pre_mapy" target="_self">
                    klikni sem
                </a>
                </p>
            </div>
            <%= Navigation.getLoginLink(request) %>
            
            <script type="text/javascript"><!--
			$(document).ready(function() {
				//toto je cela funkcia co to robi, vyvola sa pri zmene bud startu alebo ciela
				$("select.nastavovac").change(function () {
					//prefix je to co maju mapy.cz pred tym zadanim
					var prefix = 'http://www.mapy.cz/#x=137614317@y=134287748@z=6@mm=ZP@sa=r@st=r@srq=route(fast,toll):';
					//doplna sa start, vezme sa hodnota start selectu pomocou val()
					var start = $("[name=<%= START_CITY %>]").val();
					//doplna sa ciel, rovnaky postup ako pri starte
					var ciel = $("[name=<%= END_CITY %>]").val();
					//meni sa odkaz pre mapy.cz, vsimni si, ze tu pouzivam tu triedu co som deklaroval v odkaze aby som ho urcil
					$("a.odkaz_pre_mapy").attr("href", prefix + start + '>' + ciel);
		            //nastavi, aby se otevrelo nove okno po liknuti na odkaz
		            $("a.odkaz_pre_mapy").attr("target", "_blank");
				});
			});
			--></script>

</html>
